<template>
<div>
  <h1>添加分类</h1>
  <p>分类名称：<input type="text" v-model="form.name"> <button @click="add">添加</button></p>
  <h1>展示分类</h1>
  <table border="1" cellspacing="0">
    <tr>
      <td>分类名称</td>
      <td>操作</td>
    </tr>
    <tr v-for="i in fenlei">
      <td>{{i.name}}</td>
      <td>
        <button @click="del(i.id)">删除</button>
        <button @click="put(i.id,i.name)">修改</button>
      </td>
    </tr>
  </table>
  <button v-for="i in numm" @click="get(i)">{{i}}</button>
</div>
</template>

<script>
export default {
name: "lianxi",
  data(){
  return{
    form:{},
    fenlei:[],
    numm:''
    }
  },
  methods:{
  add() {
    this.$axios.post('lianxi/add', this.form).then(res => {
      if (res.data.code == 200) {
        alert('ok')
        this.get()
      }
    })
  },
    get(i){
    this.$axios.get('lianxi/add?cpage='+i).then(res=>{
      this.fenlei = res.data.list
      this.numm = res.data.total
     })
    },
    del(id){
    this.$axios.delete('lianxi/add?id='+id).then(res=>{
      if(res.data.code==200){
        alert('ok')
        this.get()
      } 
    })
    },
    put(id,name){
    this.$router.push({path:'/xiugai',query:{'id':id,'name':name}})
    }
  },
  mounted() {
  this.get(1)
  }
}
</script>

<style scoped>

</style>
